{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding=utf-8\n",
    "import pandas as pd\n",
    "import alphalens\n",
    "\n",
    "# IC大约某个值的的比例\n",
    "IC_LGT_STANDARD = 0.02\n",
    "\n",
    "MEAN_FACTOR_RETURN_STANDARD = 0.001  #因子收益率均值\n",
    "IC_MEAN_STANDARD= 0.015 #IC的均值的标准\n",
    "IC_STD_STANDARD = 0.1 #IC标准差的标注\n",
    "IC_LGTRATIO_STANDARD = 0.5 #IC大于IC_LGT_STANDARD的比例的标准\n",
    "IR_STANDARD = 0.15 #IR的标准\n",
    "\n",
    "start_date = \"20170101\"\n",
    "end_date = \"20180101\"\n",
    "stock_list = industry(\"C27\")\n",
    "\n",
    "factor_list = [\n",
    "    \"eod_derivative_indicator.pe_ratio\",\n",
    "    \"eod_derivative_indicator.pcf_ratio\",\n",
    "    \"eod_derivative_indicator.pb_ratio\",\n",
    "    \"eod_derivative_indicator.market_cap\",\n",
    "    \"eod_derivative_indicator.ps_ratio\",\n",
    "    \"financial_indicator.return_on_invested_capital\",\n",
    "    \"financial_indicator.du_return_on_equity\",\n",
    "    \"financial_indicator.return_on_asset_net_profit\",\n",
    "    \"financial_indicator.return_on_equity\",\n",
    "    \"financial_indicator.return_on_asset\",\n",
    "    \"financial_indicator.earnings_per_share\",\n",
    "    \"financial_indicator.net_profit_to_revenue\",\n",
    "    \"financial_indicator.inc_revenue\",\n",
    "    \"financial_indicator.inc_total_asset\",\n",
    "    \"financial_indicator.inc_net_profit\",\n",
    "    \"financial_indicator.inc_earnings_per_share\",\n",
    "    \"financial_indicator.inc_operating_revenue\",\n",
    "]\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "def get_cls(factor_str):\n",
    "    '''把字符串转化为对象'''\n",
    "    _befor, _after = factor_str.split(\".\")\n",
    "    temp_cls = getattr(fundamentals, _befor)\n",
    "    cls = getattr(temp_cls, _after)\n",
    "    return cls\n",
    "\n",
    "def build_factor_list():\n",
    "    factor_list = []\n",
    "    eod_derivative_indicator_ = [\"eod_derivative_indicator.\"+i for i in dir(fundamentals.eod_derivative_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(eod_derivative_indicator_)\n",
    "    income_statement_ = [\"income_statement.\"+i for i in dir(fundamentals.income_statement) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_)\n",
    "    financial_indicator_ = [\"financial_indicator.\"+i for i in dir(fundamentals.financial_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(financial_indicator_)\n",
    "    income_statement_TTM_ = [\"income_statement_TTM.\"+i for i in dir(fundamentals.income_statement_TTM) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_TTM_)\n",
    "    # factor_list = [i for i in factor_list if not i.endswith(\"date\") and not i.endswith(\"metadata\")]\n",
    "    # factor_list = [i for i in factor_list if not i.endswith(\"date\") and not i.endswith(\"metadata\") and not i[-1] in string.digits]\n",
    "    endserror = [\"rpt_quarter\",\"rpt_year\",\"stockcode\",\"date\",\"metadata\",\"enterprise_expansion_reserve\",\"exchange_gains_or_losses\"]\n",
    "    endserror.extend(list(string.digits))\n",
    "    final_list = []\n",
    "    for factor in factor_list:\n",
    "        flag = True\n",
    "        for ends in endserror:\n",
    "            if factor.endswith(ends):\n",
    "                flag = False\n",
    "        if flag:\n",
    "            final_list.append(factor)\n",
    "\n",
    "    return final_list\n",
    "\n",
    "# 1. 准备factor\n",
    "def prepar_factor(start_date, end_date, factor, stock_list):\n",
    "    '''\n",
    "    :param start_date:开始日期\n",
    "    :param end_date: 结束日期\n",
    "    :param factor: 因子名字\n",
    "    :param stock_list: 股票池\n",
    "    :return:factor数据，multiIndex的series\n",
    "    '''\n",
    "    trading_dates = get_trading_dates(start_date=start_date, end_date=end_date)\n",
    "    q = query(get_cls(factor)).filter(fundamentals.stockcode.in_(stock_list))\n",
    "    fund = get_fundamentals(q, entry_date=end_date, interval=\"{}d\".format(len(trading_dates)))\n",
    "    fund = fund[factor.split(\".\")[-1], :, :].stack()\n",
    "    # print(fund)\n",
    "    return fund\n",
    "\n",
    "\n",
    "# 2. 准备price\n",
    "def prepar_price(start_date, end_date, stock_list):\n",
    "    prices = get_price(stock_list, start_date=start_date, end_date=end_date, fields=\"close\")\n",
    "    return prices\n",
    "\n",
    "\n",
    "# 3. 获取计算IC值需要的数据格式，multiIndex的series,计算IC,计算因子收益率\n",
    "def get_IC(factor, prices):\n",
    "    factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factor, prices)\n",
    "    IC = alphalens.performance.factor_information_coefficient(factor_data)\n",
    "    factor_return = alphalens.performance.factor_returns(factor_data)\n",
    "    return factor_data, IC, factor_return\n",
    "\n",
    "\n",
    "def get_result( IC, factor_return):\n",
    "    '''\n",
    "    :param IC: 因子的IC\n",
    "    :param factor_return:因子的收益率\n",
    "    :return: mean_factor_return,IC_mean,IC_std,IC_lgtratio,IR,score\n",
    "    '''\n",
    "    # 因子收益率的均值\n",
    "    mean_factor_return = factor_return.iloc[:, 0].mean()\n",
    "    # IC的均值\n",
    "    IC_mean = IC.iloc[:, 0].mean()\n",
    "    # IC的标准差\n",
    "    IC_std = IC.iloc[:, 0].std()\n",
    "    # IC大于标准的比例\n",
    "    IC_lgtratio = IC.iloc[:, 0][IC.iloc[:, 0] > IC_LGT_STANDARD].shape[0] / IC.iloc[:, 0].shape[0]\n",
    "    # IR\n",
    "    IR = IC_mean / IC_std\n",
    "\n",
    "    #计算当前因子的得分\n",
    "    score = 0\n",
    "    if abs(mean_factor_return)>=MEAN_FACTOR_RETURN_STANDARD:\n",
    "        score+=1\n",
    "    if abs(IC_mean) >=IC_MEAN_STANDARD:\n",
    "        score+=1\n",
    "    if IC_std<=IC_STD_STANDARD:\n",
    "        score+=1\n",
    "    if IC_lgtratio>=IC_LGTRATIO_STANDARD:\n",
    "        score+=1\n",
    "    if abs(IR)>=IR_STANDARD:\n",
    "        score+=1\n",
    "\n",
    "    return mean_factor_return, IC_mean, IC_std, IC_lgtratio, IR,score\n",
    "\n",
    "\n",
    "# 计算所有的因子的结果\n",
    "def get_all_result():\n",
    "    all_result_list = []  #最终[[因子1的数据],[因子2的数据],...]\n",
    "#     factor_list = build_factor_list() #可以去获取所有的因子计算\n",
    "    for factor_str in factor_list:\n",
    "        print(factor_str)\n",
    "        #1. 准备factor\n",
    "        factor = prepar_factor(start_date, end_date, factor_str, stock_list)\n",
    "        #2. 准备价格\n",
    "        prices = prepar_price(start_date, end_date, stock_list)\n",
    "        #3. 计算IC和收益率\n",
    "        try:\n",
    "            factor_data, IC, factor_return = get_IC(factor, prices)\n",
    "            \n",
    "            #4. 得到结果\n",
    "            mean_factor_return, IC_mean, IC_std, IC_lgtratio, IR,score = get_result(IC, factor_return)\n",
    "            all_result_list.append([factor_str,mean_factor_return, IC_mean, IC_std, IC_lgtratio, IR,score])\n",
    "        except:\n",
    "            pass\n",
    "\n",
    "    all_result_df = pd.DataFrame(all_result_list,columns=[\"facotr\",\"mean_factor_return\", \"IC_mean\", \"IC_std\", \"IC_lgtratio\", \"IR\",\"score\"])\n",
    "    return all_result_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "eod_derivative_indicator.pe_ratio\n",
      "eod_derivative_indicator.pcf_ratio\n",
      "eod_derivative_indicator.pb_ratio\n",
      "eod_derivative_indicator.market_cap\n",
      "eod_derivative_indicator.ps_ratio\n",
      "financial_indicator.return_on_invested_capital\n",
      "financial_indicator.du_return_on_equity\n",
      "financial_indicator.return_on_asset_net_profit\n",
      "financial_indicator.return_on_equity\n",
      "financial_indicator.return_on_asset\n",
      "financial_indicator.earnings_per_share\n",
      "financial_indicator.net_profit_to_revenue\n",
      "financial_indicator.inc_revenue\n",
      "financial_indicator.inc_total_asset\n",
      "financial_indicator.inc_net_profit\n",
      "financial_indicator.inc_earnings_per_share\n",
      "financial_indicator.inc_operating_revenue\n"
     ]
    }
   ],
   "source": [
    "df = get_all_result()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>facotr</th>\n",
       "      <th>mean_factor_return</th>\n",
       "      <th>IC_mean</th>\n",
       "      <th>IC_std</th>\n",
       "      <th>IC_lgtratio</th>\n",
       "      <th>IR</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>eod_derivative_indicator.pe_ratio</td>\n",
       "      <td>-0.000616</td>\n",
       "      <td>-0.023112</td>\n",
       "      <td>0.117749</td>\n",
       "      <td>0.367521</td>\n",
       "      <td>-0.196285</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>eod_derivative_indicator.pcf_ratio</td>\n",
       "      <td>-0.000724</td>\n",
       "      <td>-0.015745</td>\n",
       "      <td>0.094981</td>\n",
       "      <td>0.371795</td>\n",
       "      <td>-0.165773</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>eod_derivative_indicator.pb_ratio</td>\n",
       "      <td>0.000125</td>\n",
       "      <td>-0.013038</td>\n",
       "      <td>0.116275</td>\n",
       "      <td>0.363248</td>\n",
       "      <td>-0.112128</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>eod_derivative_indicator.market_cap</td>\n",
       "      <td>0.000312</td>\n",
       "      <td>0.000623</td>\n",
       "      <td>0.216232</td>\n",
       "      <td>0.448718</td>\n",
       "      <td>0.002880</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>eod_derivative_indicator.ps_ratio</td>\n",
       "      <td>-0.000159</td>\n",
       "      <td>-0.014260</td>\n",
       "      <td>0.115399</td>\n",
       "      <td>0.423077</td>\n",
       "      <td>-0.123567</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>financial_indicator.return_on_invested_capital</td>\n",
       "      <td>0.001221</td>\n",
       "      <td>0.018168</td>\n",
       "      <td>0.134614</td>\n",
       "      <td>0.470085</td>\n",
       "      <td>0.134966</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>financial_indicator.du_return_on_equity</td>\n",
       "      <td>0.001258</td>\n",
       "      <td>0.016976</td>\n",
       "      <td>0.135526</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.125257</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>financial_indicator.return_on_asset_net_profit</td>\n",
       "      <td>0.001122</td>\n",
       "      <td>0.016129</td>\n",
       "      <td>0.132530</td>\n",
       "      <td>0.508547</td>\n",
       "      <td>0.121704</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>financial_indicator.return_on_equity</td>\n",
       "      <td>0.001258</td>\n",
       "      <td>0.016976</td>\n",
       "      <td>0.135526</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.125257</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>financial_indicator.return_on_asset</td>\n",
       "      <td>0.001201</td>\n",
       "      <td>0.017158</td>\n",
       "      <td>0.133128</td>\n",
       "      <td>0.517094</td>\n",
       "      <td>0.128884</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>financial_indicator.earnings_per_share</td>\n",
       "      <td>0.000923</td>\n",
       "      <td>0.021687</td>\n",
       "      <td>0.145436</td>\n",
       "      <td>0.529915</td>\n",
       "      <td>0.149119</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>financial_indicator.net_profit_to_revenue</td>\n",
       "      <td>0.000581</td>\n",
       "      <td>0.008453</td>\n",
       "      <td>0.103580</td>\n",
       "      <td>0.504274</td>\n",
       "      <td>0.081605</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>financial_indicator.inc_revenue</td>\n",
       "      <td>0.000054</td>\n",
       "      <td>0.005099</td>\n",
       "      <td>0.070488</td>\n",
       "      <td>0.440171</td>\n",
       "      <td>0.072338</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>financial_indicator.inc_total_asset</td>\n",
       "      <td>-0.000085</td>\n",
       "      <td>0.016466</td>\n",
       "      <td>0.103028</td>\n",
       "      <td>0.478632</td>\n",
       "      <td>0.159819</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>financial_indicator.inc_net_profit</td>\n",
       "      <td>0.000196</td>\n",
       "      <td>0.017035</td>\n",
       "      <td>0.079496</td>\n",
       "      <td>0.538462</td>\n",
       "      <td>0.214287</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>financial_indicator.inc_earnings_per_share</td>\n",
       "      <td>0.000317</td>\n",
       "      <td>0.020497</td>\n",
       "      <td>0.078697</td>\n",
       "      <td>0.487179</td>\n",
       "      <td>0.260456</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>financial_indicator.inc_operating_revenue</td>\n",
       "      <td>-0.000089</td>\n",
       "      <td>0.005405</td>\n",
       "      <td>0.072610</td>\n",
       "      <td>0.410256</td>\n",
       "      <td>0.074440</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            facotr  mean_factor_return  \\\n",
       "0                eod_derivative_indicator.pe_ratio           -0.000616   \n",
       "1               eod_derivative_indicator.pcf_ratio           -0.000724   \n",
       "2                eod_derivative_indicator.pb_ratio            0.000125   \n",
       "3              eod_derivative_indicator.market_cap            0.000312   \n",
       "4                eod_derivative_indicator.ps_ratio           -0.000159   \n",
       "5   financial_indicator.return_on_invested_capital            0.001221   \n",
       "6          financial_indicator.du_return_on_equity            0.001258   \n",
       "7   financial_indicator.return_on_asset_net_profit            0.001122   \n",
       "8             financial_indicator.return_on_equity            0.001258   \n",
       "9              financial_indicator.return_on_asset            0.001201   \n",
       "10          financial_indicator.earnings_per_share            0.000923   \n",
       "11       financial_indicator.net_profit_to_revenue            0.000581   \n",
       "12                 financial_indicator.inc_revenue            0.000054   \n",
       "13             financial_indicator.inc_total_asset           -0.000085   \n",
       "14              financial_indicator.inc_net_profit            0.000196   \n",
       "15      financial_indicator.inc_earnings_per_share            0.000317   \n",
       "16       financial_indicator.inc_operating_revenue           -0.000089   \n",
       "\n",
       "     IC_mean    IC_std  IC_lgtratio        IR  score  \n",
       "0  -0.023112  0.117749     0.367521 -0.196285      2  \n",
       "1  -0.015745  0.094981     0.371795 -0.165773      3  \n",
       "2  -0.013038  0.116275     0.363248 -0.112128      0  \n",
       "3   0.000623  0.216232     0.448718  0.002880      0  \n",
       "4  -0.014260  0.115399     0.423077 -0.123567      0  \n",
       "5   0.018168  0.134614     0.470085  0.134966      2  \n",
       "6   0.016976  0.135526     0.500000  0.125257      3  \n",
       "7   0.016129  0.132530     0.508547  0.121704      3  \n",
       "8   0.016976  0.135526     0.500000  0.125257      3  \n",
       "9   0.017158  0.133128     0.517094  0.128884      3  \n",
       "10  0.021687  0.145436     0.529915  0.149119      2  \n",
       "11  0.008453  0.103580     0.504274  0.081605      1  \n",
       "12  0.005099  0.070488     0.440171  0.072338      1  \n",
       "13  0.016466  0.103028     0.478632  0.159819      2  \n",
       "14  0.017035  0.079496     0.538462  0.214287      4  \n",
       "15  0.020497  0.078697     0.487179  0.260456      3  \n",
       "16  0.005405  0.072610     0.410256  0.074440      1  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_factor_list():\n",
    "    factor_list = []\n",
    "    eod_derivative_indicator_ = [\"eod_derivative_indicator.\"+i for i in dir(fundamentals.eod_derivative_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(eod_derivative_indicator_)\n",
    "    income_statement_ = [\"income_statement.\"+i for i in dir(fundamentals.income_statement) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_)\n",
    "    financial_indicator_ = [\"financial_indicator.\"+i for i in dir(fundamentals.financial_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(financial_indicator_)\n",
    "    income_statement_TTM_ = [\"income_statement_TTM.\"+i for i in dir(fundamentals.income_statement_TTM) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_TTM_)\n",
    "    # factor_list = [i for i in factor_list if not i.endswith(\"date\") and not i.endswith(\"metadata\")]\n",
    "    # factor_list = [i for i in factor_list if not i.endswith(\"date\") and not i.endswith(\"metadata\") and not i[-1] in string.digits]\n",
    "    endserror = [\"rpt_quarter\",\"rpt_year\",\"stockcode\",\"announce_date\",\"metadata\"]\n",
    "    endserror.extend(list(string.digits))\n",
    "    final_list = []\n",
    "    for factor in factor_list:\n",
    "        flag = True\n",
    "        for ends in endserror:\n",
    "            if factor.endswith(ends):\n",
    "                flag = False\n",
    "        if flag:\n",
    "            final_list.append(factor)\n",
    "\n",
    "    return final_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2017-12-29  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-12-28  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-12-27  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-12-26  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-12-25  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-12-22  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            002219.XSHE   -151804\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "                            ...  \n",
       "2017-01-12  000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-11  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-10  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-09  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-06  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-05  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-04  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "2017-01-03  002030.XSHE         0\n",
       "            002317.XSHE         0\n",
       "            000756.XSHE         0\n",
       "            000518.XSHE         0\n",
       "dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查因子 \"eod_derivative_indicator.announce_date\"\n",
    "factor_str=  \"income_statement.exchange_gains_or_losses\"\n",
    "factor = prepar_factor(start_date, end_date, factor_str, stock_list)\n",
    "prices = prepar_price(start_date, end_date, stock_list)\n",
    "# factor\n",
    "factor\n",
    "# factor_data, IC, factor_return = get_IC(factor, prices)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2017-10-30  000538.XSHE     70.495\n",
       "            600196.XSHG    11.7849\n",
       "            600568.XSHG   -17.2253\n",
       "            000423.XSHE     119.21\n",
       "            002107.XSHE    47.5695\n",
       "            600329.XSHG   -1224.16\n",
       "            000756.XSHE    88.7603\n",
       "            600781.XSHG    24.4708\n",
       "            603229.XSHG     6.8758\n",
       "            603707.XSHG   -23.7961\n",
       "            000566.XSHE     6.4079\n",
       "            600079.XSHG    41.8378\n",
       "            000919.XSHE      26.35\n",
       "            600488.XSHG    -14.542\n",
       "            603387.XSHG      329.9\n",
       "            600267.XSHG    -24.848\n",
       "            600613.XSHG    43.7376\n",
       "            000931.XSHE     9.5587\n",
       "            600085.XSHG    53.5314\n",
       "            002393.XSHE   -42.9231\n",
       "2017-10-27  000538.XSHE    67.9972\n",
       "            300497.XSHE    18.5069\n",
       "            300363.XSHE   -18.0558\n",
       "            600196.XSHG    12.1692\n",
       "            600568.XSHG   -17.2945\n",
       "            000423.XSHE    119.906\n",
       "            600385.XSHG   -665.397\n",
       "            002107.XSHE    48.7864\n",
       "            600222.XSHG    110.187\n",
       "            300452.XSHE    15.9505\n",
       "                            ...   \n",
       "2017-02-16  600227.XSHG    30.9666\n",
       "            002349.XSHE   -98.9661\n",
       "2017-02-15  002107.XSHE    1654.95\n",
       "            600227.XSHG    30.7909\n",
       "            002349.XSHE   -98.0521\n",
       "2017-02-14  002107.XSHE    1646.23\n",
       "            600227.XSHG    31.2741\n",
       "            002349.XSHE   -98.4874\n",
       "2017-02-13  002107.XSHE    1658.22\n",
       "            600227.XSHG    31.4937\n",
       "            002349.XSHE   -98.7485\n",
       "2017-02-10  002107.XSHE    1629.87\n",
       "            600227.XSHG    31.3619\n",
       "            002349.XSHE   -97.5299\n",
       "2017-02-09  002107.XSHE    1641.87\n",
       "            600227.XSHG    31.6694\n",
       "            002349.XSHE   -103.623\n",
       "2017-02-08  002107.XSHE    1617.88\n",
       "            600227.XSHG    31.4058\n",
       "2017-02-07  002107.XSHE    1617.88\n",
       "            600227.XSHG    30.9227\n",
       "2017-02-06  002107.XSHE    1628.78\n",
       "            600227.XSHG    30.7909\n",
       "2017-02-03  002107.XSHE    1608.07\n",
       "            600227.XSHG     30.747\n",
       "2017-01-26  002107.XSHE    1602.62\n",
       "            600227.XSHG    30.9227\n",
       "2017-01-25  002107.XSHE    1600.44\n",
       "            600227.XSHG    30.9666\n",
       "2017-01-24  600227.XSHG    30.7909\n",
       "dtype: object"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2017-12-29  000538.XSHE     2.0171e+07\n",
       "            300497.XSHE     2.0171e+07\n",
       "            002826.XSHE     2.0171e+07\n",
       "            002680.XSHE     2.0171e+07\n",
       "            600201.XSHG     2.0171e+07\n",
       "            603880.XSHG     2.0171e+07\n",
       "            300119.XSHE     2.0171e+07\n",
       "            600276.XSHG     2.0171e+07\n",
       "            300363.XSHE     2.0171e+07\n",
       "            002773.XSHE     2.0171e+07\n",
       "            002365.XSHE     2.0171e+07\n",
       "            600196.XSHG     2.0171e+07\n",
       "            603456.XSHG     2.0171e+07\n",
       "            000952.XSHE     2.0171e+07\n",
       "            300558.XSHE     2.0171e+07\n",
       "            603538.XSHG     2.0171e+07\n",
       "            300009.XSHE     2.0171e+07\n",
       "            600572.XSHG     2.0171e+07\n",
       "            000661.XSHE     2.0171e+07\n",
       "            600568.XSHG     2.0171e+07\n",
       "            002675.XSHE     2.0171e+07\n",
       "            603567.XSHG     2.0171e+07\n",
       "            000423.XSHE     2.0171e+07\n",
       "            000153.XSHE     2.0171e+07\n",
       "            600867.XSHG     2.0171e+07\n",
       "            000590.XSHE     2.0171e+07\n",
       "            600385.XSHG     2.0171e+07\n",
       "            002562.XSHE     2.0171e+07\n",
       "            300147.XSHE     2.0171e+07\n",
       "            000004.XSHE     2.0171e+07\n",
       "                              ...     \n",
       "2017-01-03  002038.XSHE     2.0161e+07\n",
       "            002275.XSHE     2.0161e+07\n",
       "            600332.XSHG     2.0161e+07\n",
       "            300108.XSHE     2.0161e+07\n",
       "            002007.XSHE     2.0161e+07\n",
       "            603520.XSHG     2.0161e+07\n",
       "            002390.XSHE     2.0161e+07\n",
       "            002099.XSHE     2.0161e+07\n",
       "            002693.XSHE     2.0161e+07\n",
       "            300573.XSHE    2.01611e+07\n",
       "            603858.XSHG     2.0161e+07\n",
       "            600056.XSHG     2.0161e+07\n",
       "            600750.XSHG     2.0161e+07\n",
       "            002262.XSHE     2.0161e+07\n",
       "            600530.XSHG     2.0161e+07\n",
       "            000518.XSHE     2.0161e+07\n",
       "            300143.XSHE     2.0161e+07\n",
       "            002688.XSHE     2.0161e+07\n",
       "            600521.XSHG     2.0161e+07\n",
       "            600085.XSHG     2.0161e+07\n",
       "            603998.XSHG     2.0161e+07\n",
       "            300519.XSHE     2.0161e+07\n",
       "            000403.XSHE     2.0161e+07\n",
       "            002102.XSHE     2.0161e+07\n",
       "            600299.XSHG     2.0161e+07\n",
       "            002393.XSHE     2.0161e+07\n",
       "            000739.XSHE     2.0161e+07\n",
       "            600252.XSHG     2.0161e+07\n",
       "            600771.XSHG     2.0161e+07\n",
       "            000597.XSHE     2.0161e+07\n",
       "dtype: object"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor=  \"eod_derivative_indicator.announce_date\"\n",
    "trading_dates = get_trading_dates(start_date=start_date, end_date=end_date)\n",
    "q = query(get_cls(factor)).filter(fundamentals.stockcode.in_(stock_list))\n",
    "fund = get_fundamentals(q, entry_date=end_date, interval=\"{}d\".format(len(trading_dates)))\n",
    "fund = fund[0, :, :].stack()\n",
    "fund"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 如何把所有的因子计算一遍"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "eod_derivative_indicator_ = [i for i in dir(fundamentals.eod_derivative_indicator) if not i.startswith(\"_\")]\n",
    "income_statement_ = [i for i in dir(fundamentals.income_statement) if not i.startswith(\"_\")]\n",
    "financial_indicator_ = [i for i in dir(fundamentals.financial_indicator) if not i.startswith(\"_\")]\n",
    "income_statement_TTM_ = [i for i in dir(fundamentals.income_statement_TTM) if not i.startswith(\"_\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['announce_date',\n",
       " 'asset_depreciation',\n",
       " 'asset_impairment',\n",
       " 'basic_earnings_per_share',\n",
       " 'cost_of_goods_sold',\n",
       " 'disposal_loss_on_asset',\n",
       " 'end_date',\n",
       " 'enterprise_expansion_reserve',\n",
       " 'exchange_gains_or_losses',\n",
       " 'fair_value_change_income',\n",
       " 'financing_expense',\n",
       " 'ga_expense',\n",
       " 'gross_profit',\n",
       " 'income_tax',\n",
       " 'interest_expense',\n",
       " 'interest_income',\n",
       " 'inventory_shrinkage',\n",
       " 'invest_income_associates',\n",
       " 'investment_income',\n",
       " 'metadata',\n",
       " 'net_operating_revenue',\n",
       " 'net_profit',\n",
       " 'net_profit_parent_company',\n",
       " 'non_operating_expense',\n",
       " 'non_operating_net_profit',\n",
       " 'non_operating_revenue',\n",
       " 'operating_expense',\n",
       " 'operating_revenue',\n",
       " 'ordinary_stock_dividends',\n",
       " 'other_income',\n",
       " 'other_operating_cost',\n",
       " 'other_operating_income',\n",
       " 'other_operating_revenue',\n",
       " 'other_surplus_reserve',\n",
       " 'pnl_adjustment',\n",
       " 'preferred_stock_dividends',\n",
       " 'profit_available_for_distribution',\n",
       " 'profit_available_for_owner_distribution',\n",
       " 'profit_before_tax',\n",
       " 'profit_from_ma',\n",
       " 'profit_from_operation',\n",
       " 'retained_profit_at_beginning',\n",
       " 'revenue',\n",
       " 'rpt_quarter',\n",
       " 'rpt_year',\n",
       " 'sales_discount',\n",
       " 'sales_tax',\n",
       " 'selling_expense',\n",
       " 'staff_incentive_welfare_reserve',\n",
       " 'statutory_welfare_reserve',\n",
       " 'stockcode',\n",
       " 'subsidy_income',\n",
       " 'total_expense',\n",
       " 'total_income',\n",
       " 'total_income_minority',\n",
       " 'total_income_parent_company',\n",
       " 'tradedate']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "income_statement_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['account_payable_turnover_days',\n",
       " 'account_payable_turnover_rate',\n",
       " 'account_receivable_turnover_days',\n",
       " 'account_receivable_turnover_rate',\n",
       " 'adjusted_diluted_earnings_per_share',\n",
       " 'adjusted_earnings_per_share',\n",
       " 'adjusted_fully_diluted_earnings_per_share',\n",
       " 'adjusted_net_profit',\n",
       " 'adjusted_profit_to_total_profit',\n",
       " 'adjusted_return_on_equity_average',\n",
       " 'adjusted_return_on_equity_diluted',\n",
       " 'adjusted_return_on_equity_weighted_average',\n",
       " 'announce_date',\n",
       " 'annual_return_on_asset',\n",
       " 'annual_return_on_asset_net_profit',\n",
       " 'annual_return_on_equity',\n",
       " 'book_value_per_share',\n",
       " 'capital_reserve_per_share',\n",
       " 'cash_flow_from_operations_per_share',\n",
       " 'cost_to_sales',\n",
       " 'current_asset_to_total_asset',\n",
       " 'current_asset_turnover',\n",
       " 'current_debt_to_total_debt',\n",
       " 'current_ratio',\n",
       " 'debt_to_asset_ratio',\n",
       " 'debt_to_equity_ratio',\n",
       " 'depreciation_and_amortization',\n",
       " 'diluted_earnings_per_share',\n",
       " 'dividend_per_share',\n",
       " 'du_asset_turnover_ratio',\n",
       " 'du_equity_multiplier',\n",
       " 'du_profit_margin',\n",
       " 'du_return_on_equity',\n",
       " 'du_return_on_sales',\n",
       " 'earned_reserve_per_share',\n",
       " 'earnings_per_share',\n",
       " 'ebit',\n",
       " 'ebit_per_share',\n",
       " 'ebit_to_debt',\n",
       " 'ebit_to_revenue',\n",
       " 'ebitda',\n",
       " 'end_date',\n",
       " 'equity_multiplier',\n",
       " 'equity_to_debt_ratio',\n",
       " 'equity_to_interest_bearing_debt',\n",
       " 'ev',\n",
       " 'ev_2',\n",
       " 'ev_to_ebit',\n",
       " 'ev_to_ebitda',\n",
       " 'expense_to_revenue',\n",
       " 'fcfe',\n",
       " 'fcff',\n",
       " 'fixed_asset_turnover',\n",
       " 'free_cash_flow_company_per_share',\n",
       " 'free_cash_flow_equity_per_share',\n",
       " 'fully_diluted_earnings_per_share',\n",
       " 'gross_profit_margin',\n",
       " 'inc_adjusted_net_profit',\n",
       " 'inc_book_per_share',\n",
       " 'inc_cash_from_operations',\n",
       " 'inc_diluted_earnings_per_share',\n",
       " 'inc_earnings_per_share',\n",
       " 'inc_gross_profit',\n",
       " 'inc_net_profit',\n",
       " 'inc_operating_revenue',\n",
       " 'inc_profit_before_tax',\n",
       " 'inc_return_on_equity',\n",
       " 'inc_revenue',\n",
       " 'inc_total_asset',\n",
       " 'income_tax_to_profit_before_tax',\n",
       " 'interest_bearing_debt',\n",
       " 'interest_bearing_debt_to_capital',\n",
       " 'inventory_turnover',\n",
       " 'invesment_profit_to_profit_before_tax',\n",
       " 'invested_capital',\n",
       " 'long_term_debt_to_working_capital',\n",
       " 'metadata',\n",
       " 'net_debt',\n",
       " 'net_profit_margin',\n",
       " 'net_profit_to_revenue',\n",
       " 'net_working_capital',\n",
       " 'non_current_asset_to_total_asset',\n",
       " 'non_current_debt_to_total_debt',\n",
       " 'non_interest_bearing_current_debt',\n",
       " 'non_interest_bearing_non_current_debt',\n",
       " 'non_operating_profit_to_profit_before_tax',\n",
       " 'non_recurring_profit_and_loss',\n",
       " 'ocf_to_current_ratio',\n",
       " 'ocf_to_debt',\n",
       " 'ocf_to_interest_bearing_debt',\n",
       " 'ocf_to_net_debt',\n",
       " 'operating_cash_flow_per_share',\n",
       " 'operating_profit_to_profit_before_tax',\n",
       " 'operating_revenue_per_share',\n",
       " 'operating_total_revenue_per_share',\n",
       " 'profit_from_operation_to_revenue',\n",
       " 'quick_ratio',\n",
       " 'retained_earnings',\n",
       " 'retained_earnings_per_share',\n",
       " 'return_on_asset',\n",
       " 'return_on_asset_net_profit',\n",
       " 'return_on_equity',\n",
       " 'return_on_equity_diluted',\n",
       " 'return_on_equity_weighted_average',\n",
       " 'return_on_invested_capital',\n",
       " 'rpt_quarter',\n",
       " 'rpt_year',\n",
       " 'stockcode',\n",
       " 'super_quick_ratio',\n",
       " 'tangible_asset_to_debt',\n",
       " 'tangible_asset_to_interest_bearing_debt',\n",
       " 'tangible_assets',\n",
       " 'time_interest_earned_ratio',\n",
       " 'total_asset_turnover',\n",
       " 'tradedate',\n",
       " 'undistributed_profit_per_share',\n",
       " 'working_capital']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "financial_indicator_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['__add__',\n",
       " '__class__',\n",
       " '__contains__',\n",
       " '__delattr__',\n",
       " '__delitem__',\n",
       " '__dir__',\n",
       " '__doc__',\n",
       " '__eq__',\n",
       " '__format__',\n",
       " '__ge__',\n",
       " '__getattribute__',\n",
       " '__getitem__',\n",
       " '__gt__',\n",
       " '__hash__',\n",
       " '__iadd__',\n",
       " '__imul__',\n",
       " '__init__',\n",
       " '__iter__',\n",
       " '__le__',\n",
       " '__len__',\n",
       " '__lt__',\n",
       " '__mul__',\n",
       " '__ne__',\n",
       " '__new__',\n",
       " '__reduce__',\n",
       " '__reduce_ex__',\n",
       " '__repr__',\n",
       " '__reversed__',\n",
       " '__rmul__',\n",
       " '__setattr__',\n",
       " '__setitem__',\n",
       " '__sizeof__',\n",
       " '__str__',\n",
       " '__subclasshook__',\n",
       " 'append',\n",
       " 'clear',\n",
       " 'copy',\n",
       " 'count',\n",
       " 'extend',\n",
       " 'index',\n",
       " 'insert',\n",
       " 'pop',\n",
       " 'remove',\n",
       " 'reverse',\n",
       " 'sort']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(income_statement_TTM_)\n",
    "# print(income_statement_TTM_.__class__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "def build_factor_list():\n",
    "    factor_list = []\n",
    "    eod_derivative_indicator_ = [\"eod_derivative_indicator.\"+i for i in dir(fundamentals.eod_derivative_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(eod_derivative_indicator_)\n",
    "    income_statement_ = [\"income_statement.\"+i for i in dir(fundamentals.income_statement) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_)\n",
    "    financial_indicator_ = [\"financial_indicator.\"+i for i in dir(fundamentals.financial_indicator) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(financial_indicator_)\n",
    "    income_statement_TTM_ = [\"income_statement_TTM.\"+i for i in dir(fundamentals.income_statement_TTM) if not i.startswith(\"_\")]\n",
    "    factor_list.extend(income_statement_TTM_)\n",
    "    factor_list = [i for i in factor_list if not i.endswith(\"date\") and not i.endswith(\"metadata\")]\n",
    "    return factor_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "factor_list = build_factor_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['eod_derivative_indicator.a_share_market_val',\n",
       " 'eod_derivative_indicator.a_share_market_val_2',\n",
       " 'eod_derivative_indicator.dividend_yield',\n",
       " 'eod_derivative_indicator.enterprise_value',\n",
       " 'eod_derivative_indicator.enterprise_value_2',\n",
       " 'eod_derivative_indicator.market_cap',\n",
       " 'eod_derivative_indicator.market_cap_2',\n",
       " 'eod_derivative_indicator.pb_ratio',\n",
       " 'eod_derivative_indicator.pcf_ratio',\n",
       " 'eod_derivative_indicator.pcf_ratio_1',\n",
       " 'eod_derivative_indicator.pcf_ratio_2',\n",
       " 'eod_derivative_indicator.pcf_ratio_3',\n",
       " 'eod_derivative_indicator.pe_ratio',\n",
       " 'eod_derivative_indicator.pe_ratio_1',\n",
       " 'eod_derivative_indicator.pe_ratio_2',\n",
       " 'eod_derivative_indicator.peg_ratio',\n",
       " 'eod_derivative_indicator.ps_ratio',\n",
       " 'eod_derivative_indicator.rpt_quarter',\n",
       " 'eod_derivative_indicator.rpt_year',\n",
       " 'eod_derivative_indicator.stockcode',\n",
       " 'eod_derivative_indicator.val_of_stk_right',\n",
       " 'income_statement.asset_depreciation',\n",
       " 'income_statement.asset_impairment',\n",
       " 'income_statement.basic_earnings_per_share',\n",
       " 'income_statement.cost_of_goods_sold',\n",
       " 'income_statement.disposal_loss_on_asset',\n",
       " 'income_statement.enterprise_expansion_reserve',\n",
       " 'income_statement.exchange_gains_or_losses',\n",
       " 'income_statement.fair_value_change_income',\n",
       " 'income_statement.financing_expense',\n",
       " 'income_statement.ga_expense',\n",
       " 'income_statement.gross_profit',\n",
       " 'income_statement.income_tax',\n",
       " 'income_statement.interest_expense',\n",
       " 'income_statement.interest_income',\n",
       " 'income_statement.inventory_shrinkage',\n",
       " 'income_statement.invest_income_associates',\n",
       " 'income_statement.investment_income',\n",
       " 'income_statement.net_operating_revenue',\n",
       " 'income_statement.net_profit',\n",
       " 'income_statement.net_profit_parent_company',\n",
       " 'income_statement.non_operating_expense',\n",
       " 'income_statement.non_operating_net_profit',\n",
       " 'income_statement.non_operating_revenue',\n",
       " 'income_statement.operating_expense',\n",
       " 'income_statement.operating_revenue',\n",
       " 'income_statement.ordinary_stock_dividends',\n",
       " 'income_statement.other_income',\n",
       " 'income_statement.other_operating_cost',\n",
       " 'income_statement.other_operating_income',\n",
       " 'income_statement.other_operating_revenue',\n",
       " 'income_statement.other_surplus_reserve',\n",
       " 'income_statement.pnl_adjustment',\n",
       " 'income_statement.preferred_stock_dividends',\n",
       " 'income_statement.profit_available_for_distribution',\n",
       " 'income_statement.profit_available_for_owner_distribution',\n",
       " 'income_statement.profit_before_tax',\n",
       " 'income_statement.profit_from_ma',\n",
       " 'income_statement.profit_from_operation',\n",
       " 'income_statement.retained_profit_at_beginning',\n",
       " 'income_statement.revenue',\n",
       " 'income_statement.rpt_quarter',\n",
       " 'income_statement.rpt_year',\n",
       " 'income_statement.sales_discount',\n",
       " 'income_statement.sales_tax',\n",
       " 'income_statement.selling_expense',\n",
       " 'income_statement.staff_incentive_welfare_reserve',\n",
       " 'income_statement.statutory_welfare_reserve',\n",
       " 'income_statement.stockcode',\n",
       " 'income_statement.subsidy_income',\n",
       " 'income_statement.total_expense',\n",
       " 'income_statement.total_income',\n",
       " 'income_statement.total_income_minority',\n",
       " 'income_statement.total_income_parent_company',\n",
       " 'financial_indicator.account_payable_turnover_days',\n",
       " 'financial_indicator.account_payable_turnover_rate',\n",
       " 'financial_indicator.account_receivable_turnover_days',\n",
       " 'financial_indicator.account_receivable_turnover_rate',\n",
       " 'financial_indicator.adjusted_diluted_earnings_per_share',\n",
       " 'financial_indicator.adjusted_earnings_per_share',\n",
       " 'financial_indicator.adjusted_fully_diluted_earnings_per_share',\n",
       " 'financial_indicator.adjusted_net_profit',\n",
       " 'financial_indicator.adjusted_profit_to_total_profit',\n",
       " 'financial_indicator.adjusted_return_on_equity_average',\n",
       " 'financial_indicator.adjusted_return_on_equity_diluted',\n",
       " 'financial_indicator.adjusted_return_on_equity_weighted_average',\n",
       " 'financial_indicator.annual_return_on_asset',\n",
       " 'financial_indicator.annual_return_on_asset_net_profit',\n",
       " 'financial_indicator.annual_return_on_equity',\n",
       " 'financial_indicator.book_value_per_share',\n",
       " 'financial_indicator.capital_reserve_per_share',\n",
       " 'financial_indicator.cash_flow_from_operations_per_share',\n",
       " 'financial_indicator.cost_to_sales',\n",
       " 'financial_indicator.current_asset_to_total_asset',\n",
       " 'financial_indicator.current_asset_turnover',\n",
       " 'financial_indicator.current_debt_to_total_debt',\n",
       " 'financial_indicator.current_ratio',\n",
       " 'financial_indicator.debt_to_asset_ratio',\n",
       " 'financial_indicator.debt_to_equity_ratio',\n",
       " 'financial_indicator.depreciation_and_amortization',\n",
       " 'financial_indicator.diluted_earnings_per_share',\n",
       " 'financial_indicator.dividend_per_share',\n",
       " 'financial_indicator.du_asset_turnover_ratio',\n",
       " 'financial_indicator.du_equity_multiplier',\n",
       " 'financial_indicator.du_profit_margin',\n",
       " 'financial_indicator.du_return_on_equity',\n",
       " 'financial_indicator.du_return_on_sales',\n",
       " 'financial_indicator.earned_reserve_per_share',\n",
       " 'financial_indicator.earnings_per_share',\n",
       " 'financial_indicator.ebit',\n",
       " 'financial_indicator.ebit_per_share',\n",
       " 'financial_indicator.ebit_to_debt',\n",
       " 'financial_indicator.ebit_to_revenue',\n",
       " 'financial_indicator.ebitda',\n",
       " 'financial_indicator.equity_multiplier',\n",
       " 'financial_indicator.equity_to_debt_ratio',\n",
       " 'financial_indicator.equity_to_interest_bearing_debt',\n",
       " 'financial_indicator.ev',\n",
       " 'financial_indicator.ev_2',\n",
       " 'financial_indicator.ev_to_ebit',\n",
       " 'financial_indicator.ev_to_ebitda',\n",
       " 'financial_indicator.expense_to_revenue',\n",
       " 'financial_indicator.fcfe',\n",
       " 'financial_indicator.fcff',\n",
       " 'financial_indicator.fixed_asset_turnover',\n",
       " 'financial_indicator.free_cash_flow_company_per_share',\n",
       " 'financial_indicator.free_cash_flow_equity_per_share',\n",
       " 'financial_indicator.fully_diluted_earnings_per_share',\n",
       " 'financial_indicator.gross_profit_margin',\n",
       " 'financial_indicator.inc_adjusted_net_profit',\n",
       " 'financial_indicator.inc_book_per_share',\n",
       " 'financial_indicator.inc_cash_from_operations',\n",
       " 'financial_indicator.inc_diluted_earnings_per_share',\n",
       " 'financial_indicator.inc_earnings_per_share',\n",
       " 'financial_indicator.inc_gross_profit',\n",
       " 'financial_indicator.inc_net_profit',\n",
       " 'financial_indicator.inc_operating_revenue',\n",
       " 'financial_indicator.inc_profit_before_tax',\n",
       " 'financial_indicator.inc_return_on_equity',\n",
       " 'financial_indicator.inc_revenue',\n",
       " 'financial_indicator.inc_total_asset',\n",
       " 'financial_indicator.income_tax_to_profit_before_tax',\n",
       " 'financial_indicator.interest_bearing_debt',\n",
       " 'financial_indicator.interest_bearing_debt_to_capital',\n",
       " 'financial_indicator.inventory_turnover',\n",
       " 'financial_indicator.invesment_profit_to_profit_before_tax',\n",
       " 'financial_indicator.invested_capital',\n",
       " 'financial_indicator.long_term_debt_to_working_capital',\n",
       " 'financial_indicator.net_debt',\n",
       " 'financial_indicator.net_profit_margin',\n",
       " 'financial_indicator.net_profit_to_revenue',\n",
       " 'financial_indicator.net_working_capital',\n",
       " 'financial_indicator.non_current_asset_to_total_asset',\n",
       " 'financial_indicator.non_current_debt_to_total_debt',\n",
       " 'financial_indicator.non_interest_bearing_current_debt',\n",
       " 'financial_indicator.non_interest_bearing_non_current_debt',\n",
       " 'financial_indicator.non_operating_profit_to_profit_before_tax',\n",
       " 'financial_indicator.non_recurring_profit_and_loss',\n",
       " 'financial_indicator.ocf_to_current_ratio',\n",
       " 'financial_indicator.ocf_to_debt',\n",
       " 'financial_indicator.ocf_to_interest_bearing_debt',\n",
       " 'financial_indicator.ocf_to_net_debt',\n",
       " 'financial_indicator.operating_cash_flow_per_share',\n",
       " 'financial_indicator.operating_profit_to_profit_before_tax',\n",
       " 'financial_indicator.operating_revenue_per_share',\n",
       " 'financial_indicator.operating_total_revenue_per_share',\n",
       " 'financial_indicator.profit_from_operation_to_revenue',\n",
       " 'financial_indicator.quick_ratio',\n",
       " 'financial_indicator.retained_earnings',\n",
       " 'financial_indicator.retained_earnings_per_share',\n",
       " 'financial_indicator.return_on_asset',\n",
       " 'financial_indicator.return_on_asset_net_profit',\n",
       " 'financial_indicator.return_on_equity',\n",
       " 'financial_indicator.return_on_equity_diluted',\n",
       " 'financial_indicator.return_on_equity_weighted_average',\n",
       " 'financial_indicator.return_on_invested_capital',\n",
       " 'financial_indicator.rpt_quarter',\n",
       " 'financial_indicator.rpt_year',\n",
       " 'financial_indicator.stockcode',\n",
       " 'financial_indicator.super_quick_ratio',\n",
       " 'financial_indicator.tangible_asset_to_debt',\n",
       " 'financial_indicator.tangible_asset_to_interest_bearing_debt',\n",
       " 'financial_indicator.tangible_assets',\n",
       " 'financial_indicator.time_interest_earned_ratio',\n",
       " 'financial_indicator.total_asset_turnover',\n",
       " 'financial_indicator.undistributed_profit_per_share',\n",
       " 'financial_indicator.working_capital',\n",
       " 'income_statement_TTM.administration_expenseTTM',\n",
       " 'income_statement_TTM.asset_impairment_lossTTM',\n",
       " 'income_statement_TTM.ebitTTM',\n",
       " 'income_statement_TTM.financial_expenseTTM',\n",
       " 'income_statement_TTM.gross_profitTTM',\n",
       " 'income_statement_TTM.net_profitTTM',\n",
       " 'income_statement_TTM.ni_from_operatingTTM',\n",
       " 'income_statement_TTM.ni_from_value_changeTTM',\n",
       " 'income_statement_TTM.non_operating_net_incomeTTM',\n",
       " 'income_statement_TTM.np_parent_company_ownersTTM',\n",
       " 'income_statement_TTM.operating_costTTM',\n",
       " 'income_statement_TTM.operating_expenseTTM',\n",
       " 'income_statement_TTM.operating_payoutTTM',\n",
       " 'income_statement_TTM.operating_profitTTM',\n",
       " 'income_statement_TTM.operating_revenueTTM',\n",
       " 'income_statement_TTM.rpt_quarter',\n",
       " 'income_statement_TTM.rpt_year',\n",
       " 'income_statement_TTM.stockcode',\n",
       " 'income_statement_TTM.total_operating_costTTM',\n",
       " 'income_statement_TTM.total_operating_revenueTTM',\n",
       " 'income_statement_TTM.total_profitTTM']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "224"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(factor_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
